#include "Module/ConnectionManagementDialog.qth"
#include "Module/ConnectionManagementDialog.moh"
#include "Module/ConnectionManagementWidget.qth"
#include "Module/ModuleRegistry.hpp"
#include "Storage/ConnectionConfigCollection.hpp"
#include <QtGui/QDialogButtonBox>
#include <QtGui/QVBoxLayout>
#include <QtGui/QPushButton>

namespace Module
{

ConnectionManagementDialog::ConnectionManagementDialog( QWidget* pParent /*= NULL*/ )
	: QDialog( pParent)
{
	this->setWindowModality( Qt::ApplicationModal);

	QVBoxLayout* pLayout = new QVBoxLayout();
	this->setLayout( pLayout);

	pConnMgmtWidget_ = new ConnectionManagementWidget;
	pLayout->addWidget( pConnMgmtWidget_);

	QDialogButtonBox* pDlgButtonBox = new QDialogButtonBox( QDialogButtonBox::Save | QDialogButtonBox::Close);
	pLayout->addWidget( pDlgButtonBox);

	connect( 
		pDlgButtonBox->button( QDialogButtonBox::Save), SIGNAL( clicked( bool)), 
		this, SLOT( saveClicked( bool)));
	connect( 
		pDlgButtonBox->button( QDialogButtonBox::Close), SIGNAL( clicked( bool)), 
		this, SLOT( closeClicked( bool)));
}

// ---------------------------------------------------------------------------------------------------------------------

void ConnectionManagementDialog::closeClicked( bool )
{
	this->saveClicked( false);
	this->close();
}

// ---------------------------------------------------------------------------------------------------------------------

void ConnectionManagementDialog::saveClicked( bool )
{
	ModuleRegistry::instance().connCfgCollection().store( ModuleRegistry::instance().CONNECTIONS_FILE_PATH);
}

} // namespace Module
